import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class GetClassMethodsInfo {
    public static void main(String[] args) {
        Method[] methods = GetClassMethodsInfo.class.getDeclaredMethods();
        for (Method method : methods) {
            System.out.println("方法名：" + method.getName());
            System.out.println("返回值类型：" + method.getReturnType().getName());
            Class[] parma = method.getParameterTypes();
            if (parma.length == 0) {
                System.out.println("该方法没有参数");
            }else {
                System.out.println("该方法的参数列表为：[");
                for (int i = 0; i < parma.length; i++) {
                    if (i != 0){
                        System.out.print(",");
                    }
                    System.out.println(parma[i].getName());
                }
                System.out.println("]");
            }

            System.out.println("访问修饰符：");
            int modifier = method.getModifiers();
            if ((modifier & Modifier.PUBLIC) == Modifier.PUBLIC) {
                System.out.println("public");
            }else if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE) {
                System.out.println("private");
            }else if ((modifier & Modifier.PROTECTED) == Modifier.PROTECTED) {
                System.out.println("protected");
            }else {
                System.out.println("default(package)");
            }

            if((modifier & Modifier.STATIC) == Modifier.STATIC) {
                System.out.println("static");
            }
            if ((modifier & Modifier.ABSTRACT) == Modifier.ABSTRACT) {
                System.out.println("abstract");
            }
            if ((modifier & Modifier.FINAL) == Modifier.FINAL) {
                System.out.println("final");
            }
            if((modifier & Modifier.SYNCHRONIZED) == Modifier.SYNCHRONIZED) {
                System.out.println("synchronized");
            }

            Class declaringClass = method.getDeclaringClass();
            System.out.println("方法声明" + declaringClass.getName());

            Class[] parameterTypes = method.getParameterTypes();
            if (parameterTypes.length > 0) {
                System.out.println("该方法抛出的异常有：[");
                for (int i = 0; i < parameterTypes.length; i++) {
                    if (i != 0){
                        System.out.print(",");
                    }
                    System.out.println(parameterTypes[i].getName());
                }
                System.out.println("]");
            }
            System.out.println("---------------------");
        }
    }
}
